package com.lingshi.shopping_manager_api.controller;

import com.lingshi.shopping.entity.Permission;
import com.lingshi.shopping.result.BaseResult;
import com.lingshi.shopping.service.PermissionService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * 权限管理
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @DubboReference
    private PermissionService permissionService;

    /**
     * 新增权限
     * @param permission 权限对象
     * @return
     */
    @PostMapping("/add")
    public BaseResult add(@RequestBody Permission permission) {
        permissionService.add(permission);
        return BaseResult.success();
    }

    /**
     * 修改权限
     * @param permission 权限对象
     * @return
     */
    @PutMapping("/update")
    public BaseResult update(@RequestBody Permission permission) {
        permissionService.update(permission);
        return BaseResult.success();
    }

    /**
     * 删除权限
     * @param pid 权限id
     * @return
     */
    @DeleteMapping("/delete")
    public BaseResult delete(Long pid) {
        permissionService.delete(pid);
        return BaseResult.success();
    }

    /**
     * 分页查询
     * @param page 页码
     * @param size 每页条数
     * @return 权限员分页对象
     */
    @GetMapping("/search")
    public BaseResult search(@RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return BaseResult.success(permissionService.search(page,size));
    }

    /**
     * 根据id查询权限
     * @param pid 权限id
     * @return 权限员对象
     */
    @GetMapping("/findById")
    public BaseResult findById(Long pid) {
        return BaseResult.success(permissionService.findById(pid));
    }

    /**
     * 查询所有权限
     * @return 权限对象集合
     */
    @GetMapping("/findAll")
    public BaseResult findAll() {
        return BaseResult.success(permissionService.findAll());
    }

}
